package com.cjkj.purchase.controller;

import com.cjkj.common.annotation.Log;
import com.cjkj.common.core.controller.BaseController;
import com.cjkj.common.core.domain.AjaxResult;
import com.cjkj.common.core.page.TableDataInfo;
import com.cjkj.common.enums.BusinessType;
import com.cjkj.common.utils.poi.ExcelUtil;
import com.cjkj.purchase.domain.PurchaseInfo;
import com.cjkj.purchase.service.IPurchaseInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 采购材料登记信息Controller
 * 
 * @author cjkj
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/purchase/info")
public class PurchaseInfoController extends BaseController
{
    @Resource
    private IPurchaseInfoService purchaseInfoService;

    /**
     * 查询采购材料登记信息列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:query')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseInfo purchaseInfo)
    {
        startPage();
        List<PurchaseInfo> list = purchaseInfoService.selectPurchaseInfoList(purchaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出采购材料登记信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "采购材料登记信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseInfo purchaseInfo)
    {
        List<PurchaseInfo> list = purchaseInfoService.selectPurchaseInfoList(purchaseInfo);
        ExcelUtil<PurchaseInfo> util = new ExcelUtil<PurchaseInfo>(PurchaseInfo.class);
        util.exportExcel(response, list, "采购材料登记信息数据");
    }

    /**
     * 获取采购材料登记信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{purchaseId}")
    public AjaxResult getInfo(@PathVariable("purchaseId") Long purchaseId)
    {
        return success(purchaseInfoService.selectPurchaseInfoByPurchaseId(purchaseId));
    }

    /**
     * 新增采购材料登记信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "采购材料登记信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseInfo purchaseInfo)
    {
        return toAjax(purchaseInfoService.insertPurchaseInfo(purchaseInfo));
    }

    /**
     * 修改采购材料登记信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "采购材料登记信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseInfo purchaseInfo)
    {
        return toAjax(purchaseInfoService.updatePurchaseInfo(purchaseInfo));
    }

    /**
     * 删除采购材料登记信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "采购材料登记信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purchaseIds}")
    public AjaxResult remove(@PathVariable Long[] purchaseIds)
    {
        return toAjax(purchaseInfoService.deletePurchaseInfoByPurchaseIds(purchaseIds));
    }
}
